/*
 * @Description:
 * @Author: chenju
 * @Date: 2021-11-08 15:37:26
 * @LastEditors: qingyang
 * @LastEditTime: 2023-06-28 17:57:54
 */
import { get, post } from '@/utils/http';
import {
  GetUsersListParams,
  GetUsersListResultModel,
  CreateOrModifyUserParams,
  GetAuthTreeListParams,
  GetAuthTreeListResultModel,
  GetUserRoleListGroupByResult
} from './model/userModel';
enum Api {
  // 用户列表（搜索）
  GET_USERS_LIST = '/upms/customer/pageCustomerUser',
  // 新建用户
  CREATE_USER = '/upms/customer/createUser',
  // 修改用户
  MODIFY_USER = '/upms/customer/modifyUser',
  // 删除用户
  DELETE_USER = '/upms/customer/deleteUser',
  // 重置密码
  RESET_PASS = '/upms/customer/resetPassword',
  // 获取用户组织树
  GET_USER_TREE_LIST = '/upms/organization/getOrganizationTreeByUser',
  // 获取树列表
  GET_AUTH_TREE_LIST = '/upms/organization/getOrganizationTree',
  // 获取分scope的用户可选角色列表（足迹、盘查等）
  GET_USER_ROLE_LIST_GROUP_BY = '/upms/role/getRoleList'
}

// 用户列表（搜索）
export const getUsersList = (params: GetUsersListParams): Promise<GetUsersListResultModel> =>
  get(Api.GET_USERS_LIST, params);

// 新建用户
export const createUser = (params: CreateOrModifyUserParams): Promise<void> =>
  post(Api.CREATE_USER, params);

// 修改用户
export const modifyUser = (params: CreateOrModifyUserParams): Promise<void> =>
  post(Api.MODIFY_USER, params);

// 删除用户
export const deleteUser = (userId: number): Promise<void> => post(Api.DELETE_USER, { userId });

// 重置密码
export const resetPassword = (userId: number): Promise<void> => post(Api.RESET_PASS, { userId });

// 获取用户组织树
export const getUserTreeList = (
  params: GetAuthTreeListParams
): Promise<GetAuthTreeListResultModel> => get(Api.GET_USER_TREE_LIST, params);
// 获取树列表
export const getAuthTreeList = (module: string): Promise<GetAuthTreeListResultModel> =>
  get(Api.GET_AUTH_TREE_LIST, { module });

// 获取分scope的用户可选角色列表（足迹、盘查等）
export const getUserRoleListGroupBy = (): Promise<GetUserRoleListGroupByResult[]> =>
  get(Api.GET_USER_ROLE_LIST_GROUP_BY);
